package day;

/**
 * 223. 矩形面积
 */
public class P223 {
    public int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {
        int outxlen = Math.max(ax1, Math.max(ax2, Math.max(bx1, bx2))) - Math.min(ax1, Math.min(ax2, Math.min(bx1, bx2)));
        int eachxLen = (ax1 > ax2 ? ax1 - ax2 : ax2 - ax1) + (bx1 > bx2 ? bx1 - bx2 : bx2 - bx1);
        int xLen = eachxLen - outxlen;
        int outylen = Math.max(ay1, Math.max(ay2, Math.max(by1, by2))) - Math.min(ay1, Math.min(ay2, Math.min(by1, by2)));
        int eachyLen = (ay1 > ay2 ? ay1 - ay2 : ay2 - ay1) + (by1 > by2 ? by1 - by2 : by2 - by1);
        int yLen = eachyLen - outylen;
        int area = Math.abs(ax1 - ax2) * Math.abs(ay1 - ay2) + Math.abs(bx1 - bx2) * Math.abs(by1 - by2);
        if (xLen > 0 && yLen > 0) {
            area -= xLen * yLen;
        }
        return area;
    }

    public static void main(String[] args) {
        int area = new P223().computeArea(-3, 0, 3, 4, 0, -1, 9, 2);
        System.out.println(area);
    }
}
